package com.dm.hdfxxt.projectmanage.service.impl;

import com.dm.hdfxxt.projectmanage.mapper.ProjectMapper;
import com.dm.hdfxxt.projectmanage.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;

    /**
         * @Description 修改登录用户密码
         * @Author zhangxue
         * @Date 8:49 2018/9/30
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> updatePassword(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        int i = projectMapper.updatePassword(param);
        if(i==1){
            StatusMap.put("Status",1);//保存成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//保存失败
        }
        return StatusMap;
    }
    /**
         * @Description 查询左侧项目树
         * @Author zhangxue
         * @Date 11:05 2018/9/28
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryProjectTree(Map<String, Object> param) {
        List<Map<String,Object>> ProjectTreeList = projectMapper.queryProjectTree(param);
        return ProjectTreeList;
    }

    /**
         * @Description 查询所有主题
         * @Author zhangxue
         * @Date 18:19 2018/10/29
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryTheme(Map<String, Object> param) {
        List<Map<String,Object>> ThemeList = projectMapper.queryTheme(param);
        return ThemeList;
    }

    /**
         * @Description 查询一级项目
         * @Author zhangxue
         * @Date 8:51 2018/9/28
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryFirstLevel(Map<String, Object> param) {
        List<Map<String,Object>> FirstLevelList = projectMapper.queryFirstLevel(param);
        return FirstLevelList;
    }

    /**
     * @Description 查询二级项目
     * @Author zhangxue
     * @Date 8:51 2018/9/28
     * @Param
     * @retrun
     **/
    @Override
    public List<Map<String, Object>> querySecondLevel(Map<String, Object> param) {
        List<Map<String,Object>> SecondLevelList = projectMapper.querySecondLevel(param);
        return SecondLevelList;
    }

    /**
         * @Description 添加一级项目
         * @Author zhangxue
         * @Date 9:02 2018/9/28
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveFirstLevel(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        int i = projectMapper.saveFirstLevel(param);
        if(i==1){
            StatusMap.put("Status",1);//保存成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//保存失败
        }
        return StatusMap;
    }

    /**
         * @Description 新增二级项目
         * @Author zhangxue
         * @Date 9:09 2018/9/28
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveSecondLevel(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        int i = projectMapper.saveSecondLevel(param);
        if(i==1){
            StatusMap.put("Status",1);//保存成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//保存失败
        }
        return StatusMap;
    }

    /**
     * @Description 位最下级项目绑定部门
     * @Author zhangxue
     * @Date 17:23 2018/9/28
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> updateProjectBm(Map<String, Object> param) {
        Map<String,Object> ResultMap = new HashMap<String, Object>();
        String FirstLevel = param.get("FirstLevel")!=null&&!"".equals(param.get("FirstLevel").toString())?param.get("FirstLevel").toString():null;
        String SecondLevel = param.get("SecondLevel")!=null&&!"".equals(param.get("SecondLevel").toString())?param.get("SecondLevel").toString():null;
        String ThirdLevel = param.get("ThirdLevel")!=null&&!"".equals(param.get("ThirdLevel").toString())?param.get("ThirdLevel").toString():null;
        if(ThirdLevel!=null){
            param.put("ID",ThirdLevel);
        }else if(SecondLevel!=null){
            param.put("ID",SecondLevel);
        }else if(FirstLevel!=null){
            param.put("ID",FirstLevel);
        }
        int i = projectMapper.updateProjectBm(param);
        if(i==1){
            ResultMap.put("Status",1);
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            ResultMap.put("Status",0);//保存失败
        }
        return ResultMap;
    }

    /**
         * @Description 根据部门查询所有需要录入信息
         * @Author zhangxue
         * @Date 9:06 2018/9/29
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryNeedInputInfo(Map<String, Object> param) {
        String Bm = param.get("Bm").toString();
        List<Map<String,Object>> ResultList = new ArrayList<Map<String, Object>>();
        if(Bm.equals("副总")){
            ResultList = projectMapper.queryNeedInputInfoFuzong(param);
        }else{
            ResultList = projectMapper.queryNeedInputInfo(param);
        }
        return ResultList;
    }

    /**
         * @Description 新增或编辑业务信息
         * @Author zhangxue
         * @Date 9:33 2018/9/29
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveServiceInfo(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        List<Map<String,Object>> queryList = projectMapper.queryExistServiceInfo(param);
        int i = 0;
        if(queryList.size()==0){
            i = projectMapper.saveServiceInfo(param);
        }else if(queryList.size()==1){
            i = projectMapper.updateServiceInfo(param);
        }
        if(i==1){
            StatusMap.put("Status",1);//保存成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//保存失败
        }
        return StatusMap;
    }

    /**
         * @Description 查询所有已录入数据
         * @Author zhangxue
         * @Date 10:38 2018/9/29
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryAllServiceDataInfos(Map<String, Object> param) {
        String EditDate = param.get("EditDate")!=null&&!"".equals( param.get("EditDate").toString())?param.get("EditDate").toString():null;
        String Store = param.get("Store")!=null&&!"".equals( param.get("Store").toString())?param.get("Store").toString():null;
        String Theme = param.get("Theme")!=null&&!"".equals( param.get("Theme").toString())?param.get("Theme").toString():null;
        String Type = param.get("Type")!=null&&!"".equals( param.get("Type").toString())?param.get("Type").toString():null;
        String FirstLevel = param.get("FirstLevel")!=null&&!"".equals( param.get("FirstLevel").toString())?param.get("FirstLevel").toString():null;
        String SecondLevel = param.get("SecondLevel")!=null&&!"".equals( param.get("SecondLevel").toString())?param.get("SecondLevel").toString():null;
        String ThirdLevel = param.get("ThirdLevel")!=null&&!"".equals( param.get("ThirdLevel").toString())?param.get("ThirdLevel").toString():null;
        //如果搜索条件全为空
        if(FirstLevel==null&&SecondLevel==null&&ThirdLevel==null){
            List<Map<String,Object>> ResultList = projectMapper.queryAllServiceDataInfos(param);
            List<Map<String,Object>> FinaList = new ArrayList<Map<String, Object>>();
            if(ResultList!=null){
                for(int i=0;i<ResultList .size();i++){
                    String PID = ResultList.get(i).get("PID").toString();
                    Map<String,Object> paramMap = new HashMap<String, Object>();
                    paramMap.put("PID",PID);
                    paramMap.put("Type",Type);
                    Map<String,Object> DiguiMap = projectMapper.queryProjectDiGui(paramMap);
                    if(DiguiMap!=null){
                        String DiguiType = DiguiMap.get("Type")!=null?DiguiMap.get("Type").toString():null;
                        String ProjectName = DiguiMap.get("ProjectName")!=null?DiguiMap.get("ProjectName").toString():null;
                        String SecondProjectName = DiguiMap.get("SecondProjectName")!=null?DiguiMap.get("SecondProjectName").toString():null;
                        String ThirdProjectName = DiguiMap.get("ThirdProjectName")!=null?DiguiMap.get("ThirdProjectName").toString():null;
                        ResultList.get(i).put("Type",DiguiType);
                        ResultList.get(i).put("ProjectName",ProjectName);
                        ResultList.get(i).put("SecondProjectName",SecondProjectName);
                        ResultList.get(i).put("ThirdProjectName",ThirdProjectName);
                        FinaList.add(ResultList.get(i));
                    }
                }
            }
            return FinaList;
        }
        //如果搜索条件一级项目不为空，其他为空
        if(FirstLevel!=null&&SecondLevel==null&&ThirdLevel==null){
            //查询递归数列
            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("FirstLevel",FirstLevel);
            List<Map<String,Object>> DiguiList = projectMapper.queryProjectDiGuiFirstLevelIsNotNull(paramMap);
            String idStr = "";
            for(int i=0;i<DiguiList.size();i++){
                if(DiguiList.get(i).get("Bm")!=null){
                    String tempStr = DiguiList.get(i).get("ID").toString();
                    idStr += ","+tempStr;
                }else if(DiguiList.get(i).get("SecondBm")!=null){
                    String tempStr = DiguiList.get(i).get("SecondID").toString();
                    idStr += ","+tempStr;
                }else if(DiguiList.get(i).get("ThirdBm")!=null){
                    String tempStr = DiguiList.get(i).get("ThirdID").toString();
                    idStr += ","+tempStr;
                }
            }
            idStr = idStr.substring(1);
            param.put("idStr",idStr);
            List<Map<String,Object>> ResultList = projectMapper.queryAllServiceDataInfosFirstLevelIsNotNull(param);
            List<Map<String,Object>> FinaList = new ArrayList<Map<String, Object>>();
            if(ResultList!=null){
                for(int i=0;i<ResultList .size();i++){
                    String PID = ResultList.get(i).get("PID").toString();
                    Map<String,Object> paramMap1 = new HashMap<String, Object>();
                    paramMap1.put("PID",PID);
                    paramMap1.put("Type",Type);
                    Map<String,Object> DiguiMap = projectMapper.queryProjectDiGui(paramMap1);
                    if(DiguiMap!=null){
                        String DiguiType = DiguiMap.get("Type")!=null?DiguiMap.get("Type").toString():null;
                        String ProjectName = DiguiMap.get("ProjectName")!=null?DiguiMap.get("ProjectName").toString():null;
                        String SecondProjectName = DiguiMap.get("SecondProjectName")!=null?DiguiMap.get("SecondProjectName").toString():null;
                        String ThirdProjectName = DiguiMap.get("ThirdProjectName")!=null?DiguiMap.get("ThirdProjectName").toString():null;
                        ResultList.get(i).put("Type",DiguiType);
                        ResultList.get(i).put("ProjectName",ProjectName);
                        ResultList.get(i).put("SecondProjectName",SecondProjectName);
                        ResultList.get(i).put("ThirdProjectName",ThirdProjectName);
                        FinaList.add(ResultList.get(i));
                    }
                }
            }
            return FinaList;
        }
        //如果搜索条件一级项目、二级项目不为空，其他为空
        if(FirstLevel!=null&&SecondLevel!=null&&ThirdLevel==null){
            //查询递归数列
            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("FirstLevel",FirstLevel);
            paramMap.put("SecondLevel",SecondLevel);
            List<Map<String,Object>> DiguiList = projectMapper.queryProjectDiGuiSecondLevelIsNotNull(paramMap);
            String idStr = "";
            for(int i=0;i<DiguiList.size();i++){
                if(DiguiList.get(i).get("SecondBm")!=null){
                    String tempStr = DiguiList.get(i).get("SecondID").toString();
                    idStr += ","+tempStr;
                }else if(DiguiList.get(i).get("ThirdBm")!=null){
                    String tempStr = DiguiList.get(i).get("ThirdID").toString();
                    idStr += ","+tempStr;
                }
            }
            idStr = idStr.substring(1);
            param.put("idStr",idStr);
            List<Map<String,Object>> ResultList = projectMapper.queryAllServiceDataInfosFirstLevelIsNotNull(param);
            List<Map<String,Object>> FinaList = new ArrayList<Map<String, Object>>();
            if(ResultList!=null){
                for(int i=0;i<ResultList .size();i++){
                    String PID = ResultList.get(i).get("PID").toString();
                    Map<String,Object> paramMap1 = new HashMap<String, Object>();
                    paramMap1.put("PID",PID);
                    paramMap1.put("Type",Type);
                    Map<String,Object> DiguiMap = projectMapper.queryProjectDiGui(paramMap1);
                    if(DiguiMap!=null){
                        String DiguiType = DiguiMap.get("Type")!=null?DiguiMap.get("Type").toString():null;
                        String ProjectName = DiguiMap.get("ProjectName")!=null?DiguiMap.get("ProjectName").toString():null;
                        String SecondProjectName = DiguiMap.get("SecondProjectName")!=null?DiguiMap.get("SecondProjectName").toString():null;
                        String ThirdProjectName = DiguiMap.get("ThirdProjectName")!=null?DiguiMap.get("ThirdProjectName").toString():null;
                        ResultList.get(i).put("Type",DiguiType);
                        ResultList.get(i).put("ProjectName",ProjectName);
                        ResultList.get(i).put("SecondProjectName",SecondProjectName);
                        ResultList.get(i).put("ThirdProjectName",ThirdProjectName);
                        FinaList.add(ResultList.get(i));
                    }
                }
            }
            return FinaList;
        }

        //如果搜索条件一级项目、二级项目、三级项目不为空，其他为空
        if(FirstLevel!=null&&SecondLevel!=null&&ThirdLevel!=null){
            //查询递归数列
            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("FirstLevel",FirstLevel);
            paramMap.put("SecondLevel",SecondLevel);
            paramMap.put("ThirdLevel",ThirdLevel);
            List<Map<String,Object>> DiguiList = projectMapper.queryProjectDiGuiThirdLevelIsNotNull(paramMap);
            String idStr = "";
            for(int i=0;i<DiguiList.size();i++){
                if(DiguiList.get(i).get("ThirdBm")!=null){
                    String tempStr = DiguiList.get(i).get("ThirdID").toString();
                    idStr += ","+tempStr;
                }
            }
            idStr = idStr.substring(1);
            param.put("idStr",idStr);
            List<Map<String,Object>> ResultList = projectMapper.queryAllServiceDataInfosFirstLevelIsNotNull(param);
            List<Map<String,Object>> FinaList = new ArrayList<Map<String, Object>>();
            if(ResultList!=null){
                for(int i=0;i<ResultList .size();i++){
                    String PID = ResultList.get(i).get("PID").toString();
                    Map<String,Object> paramMap1 = new HashMap<String, Object>();
                    paramMap1.put("PID",PID);
                    paramMap1.put("Type",Type);
                    Map<String,Object> DiguiMap = projectMapper.queryProjectDiGui(paramMap1);
                    if(DiguiMap!=null){
                        String DiguiType = DiguiMap.get("Type")!=null?DiguiMap.get("Type").toString():null;
                        String ProjectName = DiguiMap.get("ProjectName")!=null?DiguiMap.get("ProjectName").toString():null;
                        String SecondProjectName = DiguiMap.get("SecondProjectName")!=null?DiguiMap.get("SecondProjectName").toString():null;
                        String ThirdProjectName = DiguiMap.get("ThirdProjectName")!=null?DiguiMap.get("ThirdProjectName").toString():null;
                        ResultList.get(i).put("Type",DiguiType);
                        ResultList.get(i).put("ProjectName",ProjectName);
                        ResultList.get(i).put("SecondProjectName",SecondProjectName);
                        ResultList.get(i).put("ThirdProjectName",ThirdProjectName);
                        FinaList.add(ResultList.get(i));
                    }
                }
            }
            return FinaList;
        }
        return null;
    }

    /**
         * @Description 保存礼品
         * @Author zhangxue
         * @Date 18:31 2018/9/29
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveGift(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        List<Map<String,Object>> GiftList = projectMapper.queryGiftByTel(param);
        if(GiftList.size()>0){
            StatusMap.put("Status",-1);//手机号已存在
            return StatusMap;
        }
        int i = projectMapper.saveGift(param);
        if(i==1){
            StatusMap.put("Status",1);//保存成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//保存失败
        }
        return StatusMap;
    }

    /**
     * @Description 删除礼品
     * @Author zhangxue
     * @Date 18:31 2018/9/29
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> delGiftInfo(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        int i = projectMapper.delGiftInfo(param);
        if(i==1){
            StatusMap.put("Status",1);//删除成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//删除失败
        }
        return StatusMap;
    }

    /**
         * @Description 查询所有礼品
         * @Author zhangxue
         * @Date 9:50 2018/10/1
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryAllGifts(Map<String, Object> param) {
        List<Map<String,Object>> ResultList = projectMapper.queryAllGifts(param);
        return ResultList;
    }

    /**
         * @Description 根据类型查询所有一级项目金额
         * @Author zhangxue
         * @Date 9:50 2018/10/1
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryMoneyByType(Map<String, Object> param) {
        String Theme = param.get("Theme").toString();
        List<Map<String,Object>> DiGuiList = projectMapper.queryDiGuiProject(param);
        List<Map<String,Object>> SeviceList = new ArrayList<Map<String, Object>>();
        for(int i=0;i<DiGuiList.size();i++){
            Map<String,Object> DiCenMap = new HashMap<String, Object>();
            String FirstID = DiGuiList.get(i).get("ID").toString();
            String FirstProjectName = DiGuiList.get(i).get("ProjectName").toString();
            DiCenMap.put("TopID",FirstID);
            DiCenMap.put("TopProjectName",FirstProjectName);

            String SecondID = DiGuiList.get(i).get("SecondID")!=null&&!"".equals(DiGuiList.get(i).get("SecondID").toString())?DiGuiList.get(i).get("SecondID").toString():null;
            String ThirdID = DiGuiList.get(i).get("ThirdID")!=null&&!"".equals(DiGuiList.get(i).get("ThirdID").toString())?DiGuiList.get(i).get("ThirdID").toString():null;
            if(SecondID!=null){
                if(ThirdID!=null){
                    DiCenMap.put("BottomID",ThirdID);
                    String ThirdProjectName = DiGuiList.get(i).get("ThirdProjectName").toString();
                    DiCenMap.put("BottomProjectName",ThirdProjectName);
                }else{
                    DiCenMap.put("BottomID",SecondID);
                    String SecondProjectName = DiGuiList.get(i).get("SecondProjectName").toString();
                    DiCenMap.put("BottomProjectName",SecondProjectName);
                }
            }else{
                DiCenMap.put("BottomID",FirstID);
                DiCenMap.put("BottomProjectName",FirstProjectName);
            }
            SeviceList.add(DiCenMap);
        }
        for(int j=0;j<SeviceList.size();j++){
            Map<String,Object> TempServiceMap = SeviceList.get(j);
            TempServiceMap.put("Theme",Theme);
            List<Map<String,Object>> BottomMoneyList = projectMapper.quertBottomMoney(TempServiceMap);
            Integer PMoneyTotal = 0;
            for(int k=0;k<BottomMoneyList.size();k++){
                String PMoney = BottomMoneyList.get(k).get("PMoney")!=null&&!"".equals(BottomMoneyList.get(k).get("PMoney").toString())?BottomMoneyList.get(k).get("PMoney").toString():"0";
                PMoneyTotal += Integer.valueOf(PMoney);
            }

            SeviceList.get(j).put("PMoney",PMoneyTotal);
        }
        List<Map<String,Object>> ResultList = new ArrayList<Map<String, Object>>();
        for(int i=0;i<SeviceList.size();i++){
            Map<String,Object> ResultMap = new HashMap<String, Object>();
            Integer TotalMoney = 0;
            for(int j=0;j<SeviceList.size();j++){
                if(SeviceList.get(i).get("TopID").toString().equals(SeviceList.get(j).get("TopID").toString())){
                    TotalMoney += Integer.valueOf(SeviceList.get(j).get("PMoney").toString());

                }
            }
            ResultMap.put("TopID",SeviceList.get(i).get("TopID").toString());
            ResultMap.put("TopName",SeviceList.get(i).get("TopProjectName").toString());
            ResultMap.put("TotalMoney",TotalMoney);
            ResultList.add(ResultMap);
        }
        //去重
        for(int i=0;i<ResultList.size()-1;i++)  {
            for(int j=ResultList.size()- 1;j>i;j--)  {
                if(ResultList.get(j).equals(ResultList.get(i)))  {
                    ResultList.remove(j);
                }
            }
        }
        return ResultList;
    }

    @Override
    public List<Map<String, Object>> queryStoreDataInfo(Map<String, Object> param) {
        String Theme = param.get("Theme").toString();
        List<Map<String,Object>> ResultList = new ArrayList<Map<String, Object>>();
        List<Map<String,Object>> DiGuiList = projectMapper.queryDiGuiProjectByTopID(param);
        List<Map<String,Object>> SeviceList = new ArrayList<Map<String, Object>>();
        for(int i=0;i<DiGuiList.size();i++){
            Map<String,Object> DiCenMap = new HashMap<String, Object>();
            String FirstID = DiGuiList.get(i).get("ID").toString();
            String FirstProjectName = DiGuiList.get(i).get("ProjectName").toString();
            DiCenMap.put("TopID",FirstID);
            DiCenMap.put("TopProjectName",FirstProjectName);

            String SecondID = DiGuiList.get(i).get("SecondID")!=null&&!"".equals(DiGuiList.get(i).get("SecondID").toString())?DiGuiList.get(i).get("SecondID").toString():null;
            String ThirdID = DiGuiList.get(i).get("ThirdID")!=null&&!"".equals(DiGuiList.get(i).get("ThirdID").toString())?DiGuiList.get(i).get("ThirdID").toString():null;
            if(SecondID!=null){
                if(ThirdID!=null){
                    DiCenMap.put("BottomID",ThirdID);
                    String ThirdProjectName = DiGuiList.get(i).get("ThirdProjectName").toString();
                    DiCenMap.put("BottomProjectName",ThirdProjectName);
                }else{
                    DiCenMap.put("BottomID",SecondID);
                    String SecondProjectName = DiGuiList.get(i).get("SecondProjectName").toString();
                    DiCenMap.put("BottomProjectName",SecondProjectName);
                }
            }else{
                DiCenMap.put("BottomID",FirstID);
                DiCenMap.put("BottomProjectName",FirstProjectName);
            }
            SeviceList.add(DiCenMap);
        }
        //ServiceList 查询到某一一级项目下所有底层项目
        for(int i=0;i<SeviceList.size();i++){
            Map<String,Object> tempMap = new HashMap<String, Object>();
            //某一底层项目
            Map<String,Object> ServiceTempMap = SeviceList.get(i);
            ServiceTempMap.put("Theme",Theme);
            tempMap.put("ProjectName",ServiceTempMap.get("BottomProjectName").toString());
            tempMap.put("BottomID",ServiceTempMap.get("BottomID").toString());
            List<Map<String,Object>> DEHList = new ArrayList<Map<String, Object>>();
            List<Map<String,Object>> XEHList = new ArrayList<Map<String, Object>>();
            List<Map<String,Object>> BEHList = new ArrayList<Map<String, Object>>();
            List<Map<String,Object>> JHList = new ArrayList<Map<String, Object>>();
            List<Map<String,Object>> JLLList = new ArrayList<Map<String, Object>>();
            List<Map<String,Object>> BDList = new ArrayList<Map<String, Object>>();
            List<Map<String,Object>> BZList = new ArrayList<Map<String, Object>>();
            List<Map<String,Object>> XTList = new ArrayList<Map<String, Object>>();
            //通过某一底层项目查询到业务数据
            List<Map<String,Object>> DiCenServiceList = projectMapper.queryDiCenStoreAndMoney(ServiceTempMap);
            for(int j=0;j<DiCenServiceList.size();j++){
                if("东二环店".equals(DiCenServiceList.get(j).get("Store").toString())){
                    DEHList.add(DiCenServiceList.get(j));
                }else if("西二环店".equals(DiCenServiceList.get(j).get("Store").toString())){
                    XEHList.add(DiCenServiceList.get(j));
                }else if("北二环店".equals(DiCenServiceList.get(j).get("Store").toString())){
                    BEHList.add(DiCenServiceList.get(j));
                }else if("建华店".equals(DiCenServiceList.get(j).get("Store").toString())){
                    JHList.add(DiCenServiceList.get(j));
                }else if("金利来店".equals(DiCenServiceList.get(j).get("Store").toString())){
                    JLLList.add(DiCenServiceList.get(j));
                }else if("北杜店".equals(DiCenServiceList.get(j).get("Store").toString())){
                    BDList.add(DiCenServiceList.get(j));
                }else if("邢台店".equals(DiCenServiceList.get(j).get("Store").toString())){
                    XTList.add(DiCenServiceList.get(j));
                }else if("霸州店".equals(DiCenServiceList.get(j).get("Store").toString())){
                    BZList.add(DiCenServiceList.get(j));
                }
            }
            //某底层项目东二环店录入钱数
            Integer DEHTotalMoney = 0 ;
            for(int k=0;k<DEHList.size();k++){
                String DEHMoney = DEHList.get(k).get("PMoney")!=null?DEHList.get(k).get("PMoney").toString():null;
                if(DEHMoney!=null){
                    Integer tempMoney = Integer.valueOf(DEHMoney);
                    DEHTotalMoney += tempMoney;
                }
            }
            tempMap.put("DEH",DEHTotalMoney);
            //某底层项目西二环录入钱数
            Integer XEHTotalMoney = 0 ;
            for(int k=0;k<XEHList.size();k++){
                String XEHMoney = XEHList.get(k).get("PMoney")!=null?XEHList.get(k).get("PMoney").toString():null;
                if(XEHMoney!=null){
                    Integer tempMoney = Integer.valueOf(XEHMoney);
                    XEHTotalMoney += tempMoney;
                }
            }
            tempMap.put("XEH",XEHTotalMoney);
            //某底层项目北二环录入钱数
            Integer BEHTotalMoney = 0 ;
            for(int k=0;k<BEHList.size();k++){
                String BEHMoney = BEHList.get(k).get("PMoney")!=null?BEHList.get(k).get("PMoney").toString():null;
                if(BEHMoney!=null){
                    Integer tempMoney = Integer.valueOf(BEHMoney);
                    BEHTotalMoney += tempMoney;
                }
            }
            tempMap.put("BEH",BEHTotalMoney);
            //某底层项目建华店录入钱数
            Integer JHTotalMoney = 0 ;
            for(int k=0;k<JHList.size();k++){
                String JHMoney = JHList.get(k).get("PMoney")!=null?JHList.get(k).get("PMoney").toString():null;
                if(JHMoney!=null){
                    Integer tempMoney = Integer.valueOf(JHMoney);
                    JHTotalMoney += tempMoney;
                }
            }
            tempMap.put("JH",JHTotalMoney);
            //某底层项目金利来店录入钱数
            Integer JLLTotalMoney = 0 ;
            for(int k=0;k<JLLList.size();k++){
                String JLLMoney = JLLList.get(k).get("PMoney")!=null?JLLList.get(k).get("PMoney").toString():null;
                if(JLLMoney!=null){
                    Integer tempMoney = Integer.valueOf(JLLMoney);
                    JLLTotalMoney += tempMoney;
                }
            }
            tempMap.put("JLL",JLLTotalMoney);
            //某底层项目北杜店录入钱数
            Integer BDTotalMoney = 0 ;
            for(int k=0;k<BDList.size();k++){
                String BDMoney = BDList.get(k).get("PMoney")!=null?BDList.get(k).get("PMoney").toString():null;
                if(BDMoney!=null){
                    Integer tempMoney = Integer.valueOf(BDMoney);
                    BDTotalMoney += tempMoney;
                }
            }
            tempMap.put("BD",BDTotalMoney);
            //某底层项目霸州店录入钱数
            Integer BZTotalMoney = 0 ;
            for(int k=0;k<BDList.size();k++){
                String BZMoney = BZList.get(k).get("PMoney")!=null?BZList.get(k).get("PMoney").toString():null;
                if(BZMoney!=null){
                    Integer tempMoney = Integer.valueOf(BZMoney);
                    BZTotalMoney += tempMoney;
                }
            }
            tempMap.put("BZ",BZTotalMoney);
            //某底层项目邢台店录入钱数
            Integer XTTotalMoney = 0 ;
            for(int k=0;k<XTList.size();k++){
                String XTMoney = XTList.get(k).get("PMoney")!=null?XTList.get(k).get("PMoney").toString():null;
                if(XTMoney!=null){
                    Integer tempMoney = Integer.valueOf(XTMoney);
                    XTTotalMoney += tempMoney;
                }
            }
            tempMap.put("XT",XTTotalMoney);
            ResultList.add(tempMap);
        }
        return ResultList;
    }

    /**
     * @Description 录入销售总额或销售任务
     * @Author zhangxue
     * @Date 9:15 2018/11/9
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> saveDataTotal(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        List<Map<String,Object>> GiftList = projectMapper.queryDataTotal(param);
        int i = 0;
        if(GiftList.size()>0){
            i = projectMapper.updateDataTotal(param);
        }else{
            i = projectMapper.saveDataTotal(param);
        }

        if(i==1){
            StatusMap.put("Status",1);//保存成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//保存失败
        }
        return StatusMap;
    }

    /**
         * @Description 查询销售任务与销售总额
         * @Author zhangxue
         * @Date 9:52 2018/11/9
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryDataTotal(Map<String, Object> param) {
        List<Map<String,Object>> ResultList = projectMapper.queryDataTotal(param);
        return ResultList;
    }
}
